using System;
using System.Windows.Forms;
using System.Drawing;

namespace Library_management_system
{
    public partial class MainForm : Form
    {
        private string currentUser;
        public MainForm(string username)
        {
            InitializeComponent();
            currentUser = username;
            // 设置MDI客户区背景
            foreach (Control ctl in this.Controls)
            {
                if (ctl is MdiClient client)
                {
                    client.Paint += MdiClient_Paint;
                }
            }
        }

        private void MdiClient_Paint(object sender, PaintEventArgs e)
        {
            try
            {
                using (Image bg = Image.FromFile("img/bg.jpg"))
                {
                    e.Graphics.DrawImage(bg, ((MdiClient)sender).ClientRectangle);
                }
            }
            catch { /* 图片不存在时忽略 */ }
        }

        private void btnBookManagement_Click(object sender, EventArgs e)
        {
            BookManagementForm form = new BookManagementForm();
            form.MdiParent = this;
            form.Show();
        }

        private void btnReaderManagement_Click(object sender, EventArgs e)
        {
            ReaderManagementForm form = new ReaderManagementForm();
            form.MdiParent = this;
            form.Show();
        }

        private void btnStaffManagement_Click(object sender, EventArgs e)
        {
            StaffManagementForm form = new StaffManagementForm();
            form.MdiParent = this;
            form.Show();
        }

        private void btnBorrowManagement_Click(object sender, EventArgs e)
        {
            BorrowManagementForm form = new BorrowManagementForm();
            form.MdiParent = this;
            form.Show();
        }

        private void btnFineManagement_Click(object sender, EventArgs e)
        {
            FineManagementForm form = new FineManagementForm();
            form.MdiParent = this;
            form.Show();
        }

        private void btnBorrow_Click(object sender, EventArgs e)
        {
            BorrowForm form = new BorrowForm(currentUser);
            form.MdiParent = this;
            form.Show();
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            ReturnForm form = new ReturnForm(currentUser);
            form.MdiParent = this;
            form.Show();
        }

        private void btnReaderQuery_Click(object sender, EventArgs e)
        {
            ReaderQueryForm form = new ReaderQueryForm();
            form.MdiParent = this;
            form.Show();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要退出系统吗？", "退出确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Application.Exit();
            }
        }
    }
}